/**
 * 年级等级工具 - 判断年级先后顺序
 */

const gradeOrder = ['三上', '三下', '四上', '四下', '五上', '五下', '六上', '六下'];

/**
 * 获取年级索引
 */
const getGradeIndex = (grade) => {
    return gradeOrder.indexOf(grade);
};

/**
 * 判断grade1是否小于等于grade2
 */
const isGradeLessOrEqual = (grade1, grade2) => {
    return getGradeIndex(grade1) <= getGradeIndex(grade2);
};

/**
 * 获取该年级及之前的所有年级
 */
const getGradesUpTo = (grade) => {
    const index = getGradeIndex(grade);
    if (index === -1) return [];
    return gradeOrder.slice(0, index + 1);
};

/**
 * 获取年级的中文名称
 */
const getGradeName = (grade) => {
    const names = {
        '三上': '三年级上学期',
        '三下': '三年级下学期',
        '四上': '四年级上学期',
        '四下': '四年级下学期',
        '五上': '五年级上学期',
        '五下': '五年级下学期',
        '六上': '六年级上学期',
        '六下': '六年级下学期'
    };
    return names[grade] || grade;
};

module.exports = {
    gradeOrder,
    getGradeIndex,
    isGradeLessOrEqual,
    getGradesUpTo,
    getGradeName
};

